<?php
	//Ativa o Buffer que armazena o conteúdo principal da página
	ob_start();
	require_once("../autoload.php");
	$sessao = new Projeto_Sessao();
	$sessao->setSessionName("admin");
	$sessao->iniciaSessao();
        
        $cliente = new Projeto_Clientes();
?>

<form method="post">
    <fieldset>
        <legend>Clientes</legend>
        <table width="100%">
            <tr>
                <td width="10%" align="left">
                    Nome:
                </td>
                <td align="left" colspan="3">
                    <input type="text" name="txtNome" id="txtNome" size="60" />
                </td>
            </tr>
            <tr>
                <td width="10%" align="left">
                    Endere&ccedil;o:
                </td>
                <td align="left" colspan="3">
                    <input type="text" name="txtEndereco" id="txtEndereco" size="60" />
                </td>
            </tr>
            <tr>
                <td width="10%" align="left">
                    Bairro:
                </td>
                <td align="left" width="30%">
                    <input type="text" name="txtBairro" id="txtBairro" size="30" />
                </td>
                <td width="10%" align="left">
                    Cep:
                </td>
                <td align="left" width="50%">
                    <input type="text" name="txtCep" id="txtCep" size="10" />
                </td>
            </tr>
            <tr>
                <td width="10%" align="left">
                    Cidade:
                </td>
                <td align="left" width="30%">
                    <input type="text" name="txtCidade" id="txtCidade" size="30" />
                </td>
            
                <td width="10%" align="left">
                    Estado:
                </td>
                <td align="left" width="50%">
                    <input type="text" name="txtUf" id="txtUf" size="2" />
                </td>
            </tr>
            <tr>
                <td width="10%" align="left">
                    Telefone:
                </td>
                <td align="left" width="30%">
                    <input type="text" name="txtTelefone" id="txtTelefone" size="15" />
                </td>
                <td width="10%" align="left">
                    Celular:
                </td>
                <td align="left" width="50%">
                    <input type="text" name="txtCelular" id="txtCelular" size="15" />
                </td>
            </tr>
            <tr>
                <td width="10%" align="left">
                    E-mail:
                </td>
                <td align="left" colspan="3">
                    <input type="text" name="txtEmail" id="txtEmail" size="60" />
                </td>
            </tr>
            <tr>
                <td width="10%" align="left">
                    Data Nascimento:
                </td>
                <td align="left" width="30%">
                    <input type="text" name="txtDataNasc" id="txtDataNasc" size="12" />
                </td>
                <td width="10%" align="left">
                    Sexo:
                </td>
                <td align="left" width="50%">
                    <input type="text" name="txtSexo" id="txtSexo" size="10" />
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <div id="listaClientes">
            <?php
            try{
                $lista = $cliente->Lista();
            ?>
            <table width="100%" cellpadding="2" cellspacing="0">
		<tr bgcolor="#CCCCCC">
                    <th align="center">C&oacute;d.</th>
			<th align="center">Nome</th>
			<th align="center">E-mail</th>
			<th align="center">Cidade</th>
                        <th align="center">A&ccedil;&otilde;es</th>
		</tr>
		<?php
		foreach($lista as $key){
		?>
		<tr>
			<td align="center"><?php echo $key->codigo;?></td>
			<td align="left"><?php echo $key->nome;?></td>
			<td align="center"><?php echo $key->email;?></td>
                        <td align="center"><?php echo htmlentities($key->cidade);?></td>
			<td align="center" id="tdRetorno"> <input type="button" class="botao" value="Vizualizar" onclick="carregaClientes('<?php echo $key->codigo;?>')" /> </td>
		</tr>
		<?php
		}
		?>
	</table>
            <?php
            }catch(Exception $e){
		Util_Util::Mensagem($e->getMessage());
            }
            ?>
        </div>
    </fieldset>
</form>
<?php
	// conteudoDaPagina recebe o conteudo do buffer
	$conteudoDaPagina = ob_get_contents(); 
	
	// Descarta o conteudo do Buffer
	ob_end_clean(); 
	
	/* Atribuição das Variáveis da página principal*/
	$titulo = "Macrofone"; 
	
	//Include com o Template
	include("../masterpage/masterpage_admin.php");
?>